package com.mysoft.main.main.web;

import lombok.Data;

/**
 * @Author: JohnCoding
 * @Description:
 * @date: 2019/12/23 16:48
 */
@Data
public class Result<T> {
    private Integer code = 0;

    private String message = "success";

    private T data;

    public Result() {
    }

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(T data) {
        this.data = data;
    }

    public Result<T> ok(T data){
        this.setData(data);
        return this;
    }

    public Result<T> error(Integer code , String msg){
        this.setCode(code);
        this.setMessage(msg);
        return this;
    }

    public Result<T> error(T data, String message) {
        this.code = -1;
        this.message = message;
        this.data = data;
        return this;
    }

    public Result<T> error(String message) {
        this.code = -1;
        this.message = message;
        return this;
    }

    public boolean isSuccess(){
        return 0 == code ? true : false;
    }

}
